{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-28T06:39:03.060800Z",
     "start_time": "2020-08-28T06:39:03.052800Z"
    }
   },
   "outputs": [],
   "source": [
    "name = []\n",
    "sex = []\n",
    "age = []\n",
    "department = []\n",
    "work = []\n",
    "with open('简单文本例子.txt','r',encoding ='utf-8') as f:\n",
    "    content = f.readlines()\n",
    "    for line in content:\n",
    "        if 'name' in line:\n",
    "            name.append(line.split(':')[1].strip())\n",
    "        elif 'sex' in line:\n",
    "            sex.append(line.split(':')[1].strip())\n",
    "        elif 'age' in line:\n",
    "            age.append(line.split(':')[1].strip())\n",
    "        elif 'department' in line:\n",
    "            department.append(line.split(':')[1].strip())\n",
    "        elif 'work' in line:\n",
    "            work.append(line.split(':')[1].strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-28T06:39:03.084800Z",
     "start_time": "2020-08-28T06:39:03.065800Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'name\\tsex\\tage\\tdepartment\\twork'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title = ['name', 'sex', 'age', 'department', 'work']\n",
    "title_line = '\\t'.join(title)\n",
    "\n",
    "title_line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-28T06:39:03.099800Z",
     "start_time": "2020-08-28T06:39:03.086800Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['冯明山\\t男\\t39\\t无线优化团队\\tIT系统开发',\n",
       " '朱春婷\\t女\\t23\\t综合支撑团队\\tIT系统支撑',\n",
       " '徐高原\\t男\\t24\\t无线优化团队\\t无线网络优化',\n",
       " '旷显扬\\t男\\t24\\t综合支撑团队\\t数据网络维护']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content_lines = []\n",
    "for na,se,ag,de,wo in zip(name, sex, age, department, work):\n",
    "    content_lines.append('\\t'.join([na,se,ag,de,wo]))\n",
    "    \n",
    "content_lines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-28T06:39:03.118800Z",
     "start_time": "2020-08-28T06:39:03.104800Z"
    }
   },
   "outputs": [],
   "source": [
    "with open('汇总结果.txt','w') as f:\n",
    "    f.writelines(title_line+'\\n')\n",
    "    for line in content_lines:\n",
    "        f.writelines(line+'\\n')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
